package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.dao.AppFeedBackMapper;
import com.eco.fanliapp.entity.AppFeedBack;
import com.eco.fanliapp.entity.AppUser;
import com.eco.fanliapp.service.IAppFeedBackService;
import com.eco.fanliapp.vo.AppFeedBackVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppFeedBackServiceImpl extends ServiceImpl<AppFeedBackMapper, AppFeedBack> implements IAppFeedBackService {

    @Autowired
    private AppFeedBackMapper appFeedBackMapper;

    @Override
    public int insertAppFeedBack(AppFeedBack appFeedback) {
        return appFeedBackMapper.insertAppFeedBackMapper(appFeedback);
    }


    @Override
    public ServerResponse selectfeedBackList(String userName, String keyWord, String phone, int currentPage, int pageSize) {

        PageHelper.startPage(currentPage, pageSize);
        List<AppFeedBackVo> feedBackList = appFeedBackMapper.selectfeedBackList(userName, keyWord, phone);
        if (feedBackList == null) {
            return ServerResponse.createByErrorMessage("查询失败");
        }
        return ServerResponse.createBySuccess("查询成功", new PageInfo(feedBackList));
    }

    @Override
    public ServerResponse opinionManage(AppFeedBack appFeedBack) {
        appFeedBack.setUpdateTime(System.currentTimeMillis());
        int i = appFeedBackMapper.updateById(appFeedBack);
        if (i > 0) {
            return ServerResponse.createBySuccessMessage("处理成功");
        }
        return ServerResponse.createByErrorMessage("处理失败");
    }

    @Override
    public ServerResponse getopinionList(AppUser appUser, Integer pageNum, Integer pageSize) {
        pageNum = (pageNum - 1) * pageSize;
        if (appUser != null && appUser.getUserId() != null) {
            List<AppFeedBack> feedBackList = appFeedBackMapper.findfeedBackList(appUser.getUserId().toString(), pageNum, pageSize);
            if (feedBackList == null || feedBackList.size() == 0) {
                return ServerResponse.createByErrorMessage("没有反馈记录");
            } else {
                return ServerResponse.createBySuccess("查询成功", feedBackList);
            }
        }
        return ServerResponse.createByErrorMessage("查询失败");
    }
}
